package card_discount

import (
	sqlc "bp/db/sqlc"
	sharedConv "bp/internal/rpcserver/shared/conv"
	"bp/internal/service/param"
	cardDiscountGrpc "bp/rpc/gen/mwebapi/mcard_discount"
)

type CardDiscountPtrEntityToPbFunc func(*sqlc.CardDiscount) *cardDiscountGrpc.CardDiscountEntity

// ConvCardDiscountPtrEntityToPb get func of *sqlc.CardDiscount => *cardDiscountGrpc.CardDiscountEntity
func (s *CardDiscountMWebApiImp) ConvCardDiscountPtrEntityToPb(
	itemCategoryPtrs param.ItemCategoryConfigurationPtrArray,
	itemPtrs param.ItemConfigurationPtrArray,
) CardDiscountPtrEntityToPbFunc {
	return func(ptr *sqlc.CardDiscount) *cardDiscountGrpc.CardDiscountEntity {
		if ptr == nil {
			return nil
		}
		return &cardDiscountGrpc.CardDiscountEntity{
			Id:                      ptr.ID,
			OutCardId:               ptr.OutCardID,
			Name:                    ptr.Name,
			Discount:                ptr.Discount,
			IsPaused:                ptr.IsPaused,
			UseScenes:               ptr.UseScenes,
			Scope:                   ptr.Scope,
			ItemCategoryConfs:       sharedConv.ConvItemCategoryConfigurationPtrArrayEntityToPb(itemCategoryPtrs),
			ItemConfs:               sharedConv.ConvItemConfigurationPtrArrayEntityToPb(itemPtrs),
		}
	}
}